

function VerifyMsgbox()
{
	this.init=function(uid,opener)
	{
		opener==undefined?opener='frdverify':'';
		opener='open_'+opener;
		_createbox(uid,opener);
		_bind();
	}

	var _createbox=function(uid,opener)
	{
		var html=
		'<div class="verifymsgbox_board owner_'+uid+'" id="verifymsgbox_board_'+uid+'">'+
		'<!---bar--->'+
		'<div class="verifymsgbox_bar">'+
		'<div class="bar_color theme_color_'+uid+' theme_op_'+uid+'"></div>'+
		'<div class="bar_content">'+
		'<div class="verifymsgbox_barname"><img src="img/VerifyMsg/TrayMsgBox.png"/>验证消息</div>'+
		'<div class="verifymsgbox_close"></div>'+
		'<div class="verifymsgbox_mini"></div>'+
		'<div class="clear"></div>'+
		'</div>'+
		'</div>'+
		'<!---背景内容面板 open_frdverify open_grpsys 点击切换按钮后只需更改此class即可--->'+
		'<div class="verifymsgbox_cntboard '+opener+'">'+
		'<div class="verifymsgbox_cntboard_color theme_color_'+uid+' theme_op_'+uid+'"></div>'+
		'<div class="verifymsgbox_cntboard_content">'+

		'<!---切换按钮-->'+
		'<div class="verifymsgbox_title">'+
		'<div class="verifymsgbox_title_color theme_color_'+uid+'"></div><!--定义透明深度--->'+
		'<div class="verifymsgbox_title_cnt">'+
		'<div class="verifymsgbox_title_tag frdverify_tag">好友验证</div><!---利用cntboard的open控制选中-->'+
		'<div class="verifymsgbox_title_tag grpsys_tag">群系统消息</div><!---利用cntboard的open控制选中-->'+
		'<div class="clear"></div>'+
		'</div>'+
		'</div>'+
		'<!--切换页-->'+
		'<div class="verifymsgbox_content">'+
		'<div class="verifymsgbox_content_color"></div><!--白底,定义深度-->'+
		'<div class="verifymsgbox_content_cnt"><!--切换页内容板-->'+
		'<!--好友验证面板-->'+
		'<div class="verifymsgbox_detail_frdverify verifymsgbox_detail"><!---利用cntboard的open控制显示-->'+
		'<div class="verifymsgbox_detail_cntboard"><!--好友验证面板内容板-->'+
		'<div class="verifymsgbox_detail_page"><!--好友验证面板滚动页-->'+
		/*
		'<ul class="nothandle"><!--未处理信息（即未忽略且未决定是否添加好友的信息）-->'+
		'<li><!--按照天数分列-->'+
		'<p class="timehead">今天</p>'+
		'<div class="frdverify_listbox">'+
		'<div class="delthis"></div>'+
		'<div class="listhead"><img src="img/head/3_100.gif"/></div>'+
		'<div class="listinfo">'+
		'<div class="frdname"><a class="frdnamefont">heiboy嘿波壹</a><p class="frdfrom">来自临时会话</p></div>'+
		'<div class="frddetail"><div class="qzone"></div>男 80岁 广州</div>'+
		'<div class="verifymsg"><p class="verifymsgtitle">附加消息:</p>wwwwwwwwwwwwwwwwdwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww<a href="">回复</a></div>'+
		'</div>'+
		'<div class="listctrl">'+
		'<div class="ignorebtn">忽略</div>'+
		'<div class="addornot">'+
		'<div class="add">同意</div>'+
		'<div class="sp"></div>'+
		'<div class="more"></div>'+
		'</div>'+

		'<p class="ignoretips">已忽略</p>'+
		'</div>'+
		'<div class="clear"></div>'+
		'</div>'+

		'</li>'+

		'</ul>'+
		'<ul class="hashandle"><!--已忽略信息(只获取忽略但未决定是否添加好友的信息)-->'+
		'<li class="doneline">以上为待处理信息</li><!--信息处理分割线-->'+
		'<li><!--按照天数分列-->'+
		'<p class="timehead">今天</p>'+
		'<div class="frdverify_listbox ignored">'+
		'<div class="delthis"></div>'+
		'<div class="listhead"><img src="img/head/3_100.gif"/></div>'+
		'<div class="listinfo">'+
		'<div class="frdname"><a class="frdnamefont">heiboy嘿波壹</a><p class="frdfrom">来自临时会话</p></div>'+
		'<div class="frddetail"><div class="qzone"></div>男 80岁 广州</div>'+
		'<div class="verifymsg"><p class="verifymsgtitle">附加消息:</p>wwwwwwwwwwwwwwwwwwwwwwwwwwww<a href="">回复</a></div>'+
		'</div>'+
		'<div class="listctrl">'+
		'<div class="ignorebtn">忽略</div>'+
		'<div class="addornot">'+
		'<div class="add">同意</div>'+
		'<div class="sp"></div>'+
		'<div class="more"></div>'+
		'</div>'+

		'<p class="ignoretips">已忽略</p>'+
		'</div>'+
		'<div class="clear"></div>'+
		'</div>'+


		'</li>'+

		'</ul>'+
		*/
		'</div><!--好友验证面板滚动页结束-->'+
		'</div><!--好友验证面板内容板结束-->'+
		/*'<a class="verifymsgbox_detail_newtips" href="javascript:;" onClick="msgcenter.add2vbox('+uid+',\'addfrd\');">有<font color="red" class="frdverifynum">1</font>条新好友验证信息，点击刷新 <div class="closethis"></div></a><!--新到信息提示--->'+*/
		'</div><!--好友验证面板结束-->'+

		'<!--群系统消息面板-->'+
		'<div class="verifymsgbox_detail_grpsys verifymsgbox_detail"><!---利用cntboard的open控制显示-->'+
		'<div class="verifymsgbox_detail_cntboard"><!--群系统消息面板内容板-->'+
		'<div class="verifymsgbox_detail_page"><!--群系统消息面板滚动页-->'+
		/*
		'<ul class="nothandle"><!--未处理信息（即未忽略且未决定是否添加好友的信息）-->'+
		'<li><!--按照天数分列-->'+
		'<p class="timehead">今天</p>'+
		'<div class="grpsys_listbox">'+

		'<div class="listhead"><img src="img/head/3_100.gif"/></div>'+
		'<div class="listinfo">'+
		'<div class="grpevent"><a class="frdname atitle">heiboy嘿波壹</a>申请加入群<a class="opengrp_link atitle">踏遍二沙岛</a><div class="opengrp_ico"></div></div>'+

		'<div class="intromsg"><p class="intromsgtitle">附加消息:</p>GF</div>'+
		'</div>'+
		'<div class="listctrl">'+
		'<div class="addornot">'+
		'<div class="add">同意</div>'+
		'<div class="sp"></div>'+
		'<div class="more"></div>'+
		'</div>'+
		'<a class="ignorelink" href="#" title="忽略">忽略</a>'+
		'</div>'+
		'<div class="clear"></div>'+
		'</div>'+

		'</li>'+

		'</ul>'+
		'<ul class="hashandle"><!--已忽略信息(只获取忽略但未决定是否添加好友的信息)-->'+
		'<li class="doneline">以上为待处理信息</li><!--信息处理分割线-->'+
		'<li><!--按照天数分列-->'+
		'<p class="timehead">今天</p>'+
		'<div class="grpsys_listbox ignored creategrptips">'+

		'<div class="listhead"><img src="img/head/3_100.gif"/></div>'+
		'<div class="listinfo">'+
		'<div class="grpname">您已经成功创建群<a class="opengrp_link atitle">踏遍二沙岛</a>，试试<a class="sharegrp_link">分享群</a>给大家吧</div>'+

		'<div class="intromsg"><p class="intromsgtitle">立即设置</p><a class="spreadgrp_link">群推广链接</a></div>'+
		'</div>'+
		'<div class="listctrl">'+
		'<div class="invifrdbtn">邀请好友</div>'+
		'</div>'+
		'<div class="clear"></div>'+
		'</div>'+
		'<div class="grpsys_listbox ignored">'+

		'<div class="listhead"><img src="img/head/3_100.gif"/></div>'+
		'<div class="listinfo">'+
		'<div class="grpevent"><a class="frdname atitle">heiboy嘿波壹</a>申请加入群<a class="opengrp_link atitle">踏遍二沙岛</a><div class="opengrp_ico"></div></div>'+

		'<div class="intromsg"><p class="intromsgtitle">附加消息:</p>GF</div>'+
		'</div>'+
		'<div class="listctrl">'+
		'<div class="addornot">'+
		'<div class="add">同意</div>'+
		'<div class="sp"></div>'+
		'<div class="more"></div>'+
		'</div>'+
		'<p class="ignoretips">已忽略</p>'+
		'</div>'+
		'<div class="clear"></div>'+
		'</div>'+

		'</li>'+

		'</ul>'+
		*/
		'</div><!--群系统消息面板滚动页结束-->'+
		'</div><!--群系统消息面板内容板结束-->'+

		'<a class="verifymsgbox_detail_newtips" href="javascript:;" onClick="msgcenter.add2vbox('+uid+',\'grpsys\');">有<font color="red" class="grpsysnum">1</font>条新群系统消息信息，点击刷新 <div class="closethis"></div></a><!--新到信息提示--->'+
		'</div><!--群系统消息面板结束-->'+

		'</div><!--切换页内容板结束-->'+
		'</div><!--切换页结束-->'+

		'<!---底部提示-->'+
		'<div class="verifymsgbox_bottom theme_color_'+uid+'"><!--themecolor底-->'+
		'<div class="verifymsgbox_bottom_white"></div><!---白底，定义深度-->'+
		'<div class="verifymsgbox_bottom_cnt"><!---利用cntboard的open控制显示-->'+
		'<a href="javascript:;">清空列表</a>'+
		'<a href="javascript:;">好友验证方式设置</a>'+
		'</div>'+
		'</div>'+
		'</div>'+
		'</div>'+
		'</div>';

		$('body').append(html);
		//设置顶部bar色
		var th=usr.getpro(uid,'theme');
		$('#verifymsgbox_board_'+uid+' .theme_color_'+uid).css('background',th['bgcolor']);
		$('#verifymsgbox_board_'+uid+' .theme_op_'+uid).css("filter","alpha(opacity="+th['skinopacity']+")").css("-moz-opacity",(th['skinopacity']/100)).css("opacity",(th['skinopacity']/100));

	}


	var _bind=function()
	{
		//设置拖动
		drag($(".verifymsgbox_board"));

		$('.verifymsgbox_board').click(function(e)
		{
			var t=$(e.target);
			if(t.attr('class')!='verifymsg_moreselect')
			{
				$(this).find('.addornotbox').css('display','none');
			}
		});

		//关闭
		$('.verifymsgbox_close').click(function()
		{
			$(this).parents('.verifymsgbox_board').remove();
		});
		//最小化
		$('.verifymsgbox_mini').click(function()
		{
			$(this).parents('.verifymsgbox_board').css('display','none');
		});

		//切换按钮
		$('.verifymsgbox_title_tag').click(function(e)
		{
			if($(this).hasClass('frdverify_tag'))
			{
				$(this).parents('.verifymsgbox_cntboard').removeClass('open_grpsys').addClass('open_frdverify');
			}
			else if($(this).hasClass('grpsys_tag'))
			{
				$(this).parents('.verifymsgbox_cntboard').removeClass('open_frdverify').addClass('open_grpsys');
			}

			e.stopImmediatePropagation();
		});

		//设置滚动
		$(".verifymsgbox_detail").mouseover(function()
		{
			Scroll.set($(this),$(this).find(".verifymsgbox_detail_cntboard"),$(this).find(".verifymsgbox_detail_page"));
		});

		


	}


}

//【发送】对好友验证消息的操作 ignore/accept/refuse/oneadd，(用户id，验证信息id，类型)
var _verify_select=function(uid,vid,type,more)
{
	if(type=="ignore")
	{
		_aj(vid,type,function(m)
		{
			_changefrdverifystats(uid,vid,'ignored');

		});

	}
	else if(type=="accept")
	{
		//同意验证,更新验证信息为isadd=1，添加一个新的好友数据库条目(fid,备注名，到哪个分组，是否允许进空间)，更新到页面mainboard(好友列表，最近联系)中，更改此验证消息的显示情况
		_aj(vid,type,function(m)
		{
			//将该好友添加到全局数组中
			usr.addother(uid,m);
			//console.log('同意验证并添加其为好友');
			//console.log(usr.getother(uid));
			//更新到页面mainboard(好友列表，最近联系)中
			var gid=parseInt(m.gid)==0?'default_'+uid:m.gid;
			$("#ico_contacts_"+uid+" #frdgrp_"+gid+" .frdcontent").append(
			'<div class="fds normal fds_online" name="frd_'+m.frdid+'">'+
			'<div class="imagehead"><img src="'+m.img30+'"/><div class="frdolflag"></div></div>'+
			'<div class="frdmore"></div>'+
			'<div class="detail">'+
			'<div class="frdname">'+(m.frdname.length<=0?m.name:m.frdname)+'</div>'+
			'<div class="frdnew">'+m.sign+'</div>'+
			'</div>'+
			'</div>');
			//绑定事件
			_bindFdsClick();

			var dt=new Date();
			var o={
			content: "我们已经是好友了，现在开始对话吧！",
			fromid: m.frdid,
			mode: "newadd",
			time:dt.getFullYear()+'/'+(dt.getMonth()+1)+'/'+dt.getDate()+','+(dt.getHours()<10?'0'+dt.getHours():dt.getHours())+':'+(dt.getMinutes()<10?'0'+dt.getMinutes():dt.getMinutes())+':'+(dt.getSeconds()<10?'0'+dt.getSeconds():dt.getSeconds()),
			toid: uid,
			type: "newadd",
			};
			usr.addmsg(uid,m.frdid,o,'frd');
			msgcenter.msgbox.add(uid,o,'frd');
			//console.log('同意按钮并创建如下信息');
			//console.log(o);
			//开启提示音
			$('#gotamsg')[0].play();

			//,闪烁消息,更改此验证消息的显示情况
			_changefrdverifystats(uid,vid,'hasadd');


		},more);
		

	}
	else if(type=="refuse")
	{
		//console.log('拒绝'+type);
		_aj(vid,type,function(m)
		{
			//更改此验证消息的显示情况
			_changefrdverifystats(uid,vid,'refused');
		},more);
	}
	else if(type=="oneadd")
	{
		if($("#validate_boxjs").length<=0)
		{
			$('body').append('<script id="validate_boxjs" type="text/javascript" src="js/validatebox.js"></script>');
		}
		_ajaxget('t=stranger&&u='+more,'getuser',function(m)
		{
			new ValidateBox(uid).init(m);
			$('#verifymsgbox_board_'+uid).remove();
		});
	}

	
}

//改变页面上验证消息条目的显示状态 ignored/hasadd/refused/oneadd
var _changefrdverifystats=function(uid,vid,type)
{
	var vpage=$('#verifymsgbox_board_'+uid+' .verifymsgbox_detail_frdverify .verifymsgbox_detail_page');
	var handleboard=vpage.find('.hashandle');
	var tsboard=vpage.find('.nothandle div[vid='+vid+']');
	var fid=tsboard.attr('fid');
	//console.log(tsboard[0].toString());
	var date=tsboard.parent('li').attr('date');
	var now=new Date().getFullYear()+'-'+(new Date().getMonth()+1)+'-'+(new Date().getDate()<10?'0'+new Date().getDate():new Date().getDate());
	//type=="ignore"?type='ignored':'';
	if(handleboard.length>0)//如果已经有忽略信息板
	{
		if(handleboard.find('li[date="'+date+'"]').length<=0)//如果没有日期板
		{
			var showdate=null;
			if(now==date)
			{
				showdate='今天';
			}
			else if(now=date-1)
			{
				showdate='昨天';
			}
			else
			{
				showdate=date;
			}
			handleboard.find('.doneline').after(
			'<li date="'+date+'">'+
			'<p class="timehead">'+showdate+'</p>'+
			//listbox+
			'</li>'
			);
		}
		
		handleboard.find('li[date="'+date+'"] .timehead').after('<div class="frdverify_listbox '+type+'" fid="'+fid+'" vid="'+vid+'">'+tsboard.html()+"</div>");
		tsboard.remove();
	}
	else//还没有忽略信息板
	{
		var showdate=null;
		if(now==date)
		{
			showdate='今天';
		}
		else if(now=date-1)
		{
			showdate='昨天';
		}
		else
		{
			showdate=date;
		}
		var hb=
		'<ul class="hashandle">'+
		'<li class="doneline">以上为待处理信息</li>'+
		'<li date="'+date+'">'+
		'<p class="timehead">'+showdate+'</p>'+
		//listbox+
		'</li>'+
		'</ul>';
	
		vpage.append(hb);
		vpage.find('.hashandle li[date="'+date+'"] .timehead').after('<div class="frdverify_listbox '+type+'" fid="'+fid+'" vid="'+vid+'">'+tsboard.html()+"</div>");
		
	}
	tsboard.remove();
	vpage.find('.nothandle li[date="'+date+'"] .frdverify_listbox').length<=0?vpage.find('.nothandle li[date="'+date+'"]').remove():'';
	vpage.find('.nothandle .frdverify_listbox').length<=0?vpage.find('.nothandle').remove():'';

}






//删除单条未处理验证消息
var _deleteThisVerify=function(vid,o)
{
	var o=$(o);
	_aj(vid,'delone',function(m)
	{	
		var fl=o.parents('.frdverify_listbox');
		var li=fl.parent('li');
		var ul=li.parent('ul');
		var page=ul.parent('.verifymsgbox_detail_page');
		if(ul.find('.frdverify_listbox').length==1)
		{
			ul.remove();
		}
		else
		{
			if(li.find('.frdverify_listbox').length==1)
			{
				li.remove();
			}
			else
			{
				fl.remove();
			}
		}

		if(page.find('ul').length<=0)
		{
			page.html('<div class="verifymsgbox_notmsg"></div>');
		}
			
	});
	
}

function _aj(vid,type,callback,more)
{
	$.ajax({
	url:'action/verifymsg_set.php',
	method:'POST',
	dataType:'json',
	data:'v='+vid+'&&t='+type+'&&'+more,
	success:function(m)
	{
		if(m)
		{
			callback(m);
		}else
		{
			console.log(type+'操作验证信息出错');
		}

	}
	,
	error:function()
	{
		console.log('网络或程序出错');
	}
	,
	});

}












//创建验证消息子盒子框函数
function createVerifySubBox(uid,vid,type)
{

	if($("#verifymsgbox_"+(type=="accept"?'add':'refuse')+"box_"+uid).length>0)
	{
		$("#verifymsgbox_"+(type=="accept"?'add':'refuse')+"box_"+uid).trigger('click');
		return false;
	}
	var html=
	'<div class="verifymsgbox_subwindow verifymsgbox_'+(type=="accept"?'add':'refuse')+'box" id="verifymsgbox_'+(type=="accept"?'add':'refuse')+'box_'+uid+'" vid="'+vid+'">'+
	'<div class="verifymsgbox_subwindowbar">'+
	'<div class="bar_color theme_color_'+uid+' theme_op_'+uid+'"></div>'+
	'<div class="bar_content">'+
	'<div class="verifymsgbox_barname"><img src="img/all_logo16-xp-2014.ico"/>'+(type=="accept"?'添加':'拒绝')+'</div>'+
	'<div class="verifymsgbox_subwindowclose"></div>'+
	'<div class="clear"></div>'+
	'</div>'+
	'</div>'+
	'<div class="verifymsgbox_subwindowcnt">';
	
	
	if(type=="accept")
	{
		html+=
		'<div class="baknamecnt">备注姓名:&nbsp;<input type="text" name="bakname" class="bakname"/></div>'+
		'<div class="togrp">分&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;组:&nbsp;'+
		'<span class="addfrdselectgrp">'+
		'<select name="selectgrp" class="selectgrp">';
		//获取所有组
		var gps=usr.getpro(uid,'frdgrp');
		//如果没有分组，则是默认‘我的好友’分组
		var selectstr='<option value="0">我的好友</option>';
		if(gps.length>0)
		{
			for(var i=0;i<gps.length;i++)
			{
				selectstr+='<option value="'+gps[i].id+'">'+gps[i].gname+'</option>';
			}
		}
		html+=selectstr;


		html+=
		//'<option value="0">默认分组</option>'+
		'</select>'+
		'</span>'+
		'<a href="javascript:addgrp('+uid+');">新建</a>'+
		'</div>'+
		'<div class="acc_to_space"><div class="ck"></div>不允许此人访问我的空间</div>';
	}
	else if(type=="refuse")
	{
		html+=
		'<div class="refusestrcnt">拒绝理由:&nbsp;<input type="text" name="refusestr" class="refusestr"/></div>'+
		'<div class="refuseupnow"><div class="ck"></div>拒绝再接受此人请求</div>'+
		'<p><a href="">举报</a>该用户</p>';

	}
	else
	{
		return false;
	}
	html+=
	'</div>'+
	'<div class="verifymsgbox_subwindowfoot theme_color_'+uid+'">'+
	'<div class="verifymsgbox_subwindowfootglass"></div>'+
	'<div class="verifymsgbox_subwindowfootcnt">'+
	'<div class="verifymsgbox_subwindowbutton verifymsgbox_subconfirm verifymsgbox_'+type+'btn selected">确定</div>'+
	'<div class="clear"></div>'+
	'</div>'+
	'</div>'+
	'</div>';

	$('body').append(html);
	var vb=$("#verifymsgbox_"+(type=="accept"?'add':'refuse')+"box_"+uid);
	//调色
	var th=usr.getpro(uid,'theme');
	vb.find('.theme_color_'+uid).css('background',th['bgcolor']);
	vb.find('.theme_op_'+uid).css("filter","alpha(opacity="+th['skinopacity']+")").css("-moz-opacity",(th['skinopacity']/100)).css("opacity",(th['skinopacity']/100));
	//确定位置
	var vmb=$("#verifymsgbox_board_"+uid);
	vmb.append('<div class="displayboard"></div>');
	var l=vmb[0].offsetLeft+((600-260)/2);
	var t=vmb[0].offsetTop+((476-166)/2);
	vb.css('top',t+'px').css('left',l+'px');
	
	//公共绑定事件
	drag($(".verifymsgbox_"+(type=="accept"?'add':'refuse')+"box"));
	$('.verifymsgbox_subwindowclose').click(function()
	{
		var uid=$(this).parents('.verifymsgbox_subwindow').attr('id').replace(/verifymsgbox_(\w+)_(\d+)/i,'$2');
		$("#addgrpbox_"+uid).remove();
		$(this).parents('.verifymsgbox_subwindow').remove();
		$("#verifymsgbox_board_"+uid+' .displayboard').remove();
	});
	$('.displayboard').click(function()
	{
		$('#goading')[0].play();
	});

	//点选事件
	$('.verifymsgbox_addbox .acc_to_space').click(function(e)
	{
		if($(this).find('.ck').hasClass('checked'))
		{
			$(this).find('.ck').removeClass('checked');
		}
		else
		{
			$(this).find('.ck').addClass('checked');
		}
	});
	$('.verifymsgbox_refusebox .refuseupnow').click(function(e)
	{
		if($(this).find('.ck').hasClass('checked'))
		{
			$(this).find('.ck').removeClass('checked');
		}
		else
		{
			$(this).find('.ck').addClass('checked');
		}
	});

	//确定事件
	if(type=="accept")
	{
		$('.verifymsgbox_acceptbtn').click(function(e)
		{
			var vmb=$(this).parents('.verifymsgbox_addbox');
			var bak=vmb.find('.bakname').val();
			var togrp=vmb.find('option:selected').val();
			var acc_2_sp=vmb.find('.acc_to_space .checked').length;
			var vid=vmb.attr('vid');
			var uid=vmb.attr('id').replace('verifymsgbox_addbox_','');

			_verify_select(uid,vid,'accept','bak='+bak+'&&tog='+togrp+'&&a2s='+acc_2_sp);
			vmb.remove();
			$("#verifymsgbox_board_"+uid+' .displayboard').remove();
			e.stopImmediatePropagation();
		});
	}
	else if(type=="refuse")
	{
		$('.verifymsgbox_refusebtn').click(function(e)
		{
			var vmb=$(this).parents('.verifymsgbox_refusebox');
			var restr=vmb.find('.refusestr').val();
			
			var refuseupnow=vmb.find('.refuseupnow .checked').length;
			var vid=vmb.attr('vid');
			var uid=vmb.attr('id').replace('verifymsgbox_refusebox_','');

			_verify_select(uid,vid,'refuse','restr='+restr+'&&never='+refuseupnow);
			vmb.remove();
			$("#verifymsgbox_board_"+uid+' .displayboard').remove();
			e.stopImmediatePropagation();
		});
	}


}





/*添加一个好友分组框*/
function addgrp(uid)
{
	new v_Addgrpbox().init(uid);
}
/*好友分组添加框*/
function v_Addgrpbox()
{
	this.init=function(uid)
	{
		_create(uid);
		_bindbox();
	}
	var _create=function(uid)
	{
		if($("#addgrpbox_"+uid).length>0)
		{
			$("#addgrpbox_"+uid)[0].focus();
			return false;
		}
		$('body').append(		
		'<div class="addgrpbox" id="addgrpbox_'+uid+'">'+
		'<div class="addgrpbar">'+
		'<div class="bar_color theme_color_'+uid+' theme_op_'+uid+'"></div>'+
		'<div class="bar_content">'+
		'<div class="addgrpbarname"><img src="img/all_logo16-xp-2014.ico"/>好友分组</div>'+
		'<div class="addgrpclose"></div>'+
		'</div>'+
		'</div>'+
		'<div class="grpcontent">'+
		'<p>分组名称:</p>'+
		'<input type="text" name="grpinput" class="addgrpinput"/>'+
		'</div>'+
		'<div class="gotoaddgrp theme_color_'+uid+'">'+
		'<div class="gotoaddgrpwhite"></div>'+
		'<div class="gotoaddgrpcnt">'+
		'<div class="addgrpcancelbtn">取消</div>'+
		'<div class="addgrpacceptbtn disable">确定</div>'+
		'</div>'+
		'</div>'+
		'</div>'
		);

		var vmb=$("#verifymsgbox_board_"+uid);
		
		var l=vmb[0].offsetLeft+((600-326)/2);
		var t=vmb[0].offsetTop+((476-152)/2);

		$("#addgrpbox_"+uid).css('top',t+"px").css('left',l+"px");

		var th=usr.getpro(uid,'theme');
		$("#addgrpbox_"+uid).find('.theme_color_'+uid).css('background',th['bgcolor']);
		$("#addgrpbox_"+uid).find('.theme_op_'+uid).css("filter","alpha(opacity="+th['skinopacity']+")").css("-moz-opacity",(th['skinopacity']/100)).css("opacity",(th['skinopacity']/100));
	}

	var _bindbox=function()
	{
		drag($('.addgrpbox'));
		$('.addgrpclose').click(function()
		{
			$(this).parents('.addgrpbox').remove();
		});
		$('.addgrpcancelbtn').click(function()
		{
			$(this).parents('.addgrpbox').remove();
		});
	

		$(".addgrpinput").keyup(function()
		{
			if($.trim($(this).val()).length>0)
			{
				$(this).parents('.addgrpbox').find('.addgrpacceptbtn').removeClass('disable');
			}
			else
			{
				$(this).parents('.addgrpbox').find('.addgrpacceptbtn').addClass('disable');
			}
		});

		$('.addgrpacceptbtn').click(function()
		{
			if($(this).hasClass('disable'))
			{
				$(this).parents('.addgrpbox').find('.addgrpinput')[0].focus();
				return false;
			}
			var str=$.trim($(this).parents('.addgrpbox').find('.addgrpinput').val());
			if(str.length<=0)
			{
				$(this).addClass('disable');
				$(this).parents('.addgrpbox').find('.addgrpinput')[0].focus();
				return false;
			}
			
			var uid=$(this).parents('.addgrpbox').attr('id').replace('addgrpbox_','');
			var reg=/addgrpbox_(\d+)_(\d+)/;
			var pt=$(this).parents('.addgrpbox');

			//提交数据后马上解绑，防止多次点击提交
			$(this).addClass('disable').unbind('click');

			//提交新建分组数据并更改页面中分组情况

			$.ajax(
			{
			url:'action/frdvalidate.php',
			type:'POST',
			data:'u='+uid+'&&t=addgrp'+'&&g='+str,
			dataType:'json',
			success:function(msg)
			{
				if(msg!='no')
				{
					var gid=msg;
					//添加到全局对象数组中
					var oldgps=usr.getpro(uid,'frdgrp');
					oldgps.push({frdcount:'0',gname:str,id:gid,ownid:uid});
					usr.setpro(uid,'frdgrp',oldgps);

					//添加到选择框中
					$('#verifymsgbox_addbox_'+uid+' .selectgrp').append('<option value="'+gid+'" selected>'+str+'</option>');

					//添加到主面板中
					$("#ico_contacts_"+uid+" .contacts_page").append(
					'<div class="groups" id="frdgrp_'+gid+'">'+
					'<div class="grphead">'+
					'<div class="grp_putdown"><img src="img/mainpanel/0.png"/></div>'+
					'<div class="grpname">'+str+'</div>'+
					'<div class="frdsum">0/0</div>'+
					'<div class="clear"></div></div>'+
					'<div class="frdcontent"></div></div>'
					);
					$('#frdgrp_'+gid+' .grphead').click(function()
					{
						if($(this).next(".frdcontent").css("display")=="block")
						{
							$(this).find(".grp_putdown").html('<img src="img/mainpanel/0.png"/>');
							$(this).next(".frdcontent").css("display","none");
						}
						else
						{						
							$(this).find(".grp_putdown").html('<img src="img/mainpanel/90.png"/>');
							$(this).next(".frdcontent").css("display","block");
						}
					});
					pt.remove();
				}

			},
			error:function()
			{

			}
			});
			


			
		});



	}
}